<h3 class="title"> &nbsp;首页 &gt; <a href="<?=Base::adminUrl('zone', 'index');?>">区域管理</a> &gt;
  <?php
	$acts = array(
		'create' => '添加',
		'modify' => '编辑',
	);
	echo $acts[$action];
?>
</h3>
<form method="post" name="form1" action="<?=Base::adminUrl('zone', 'process');?>"  onsubmit="return checkSubmit();">
  <input type="hidden" name="action" value="<?=$action;?>" />
  <input type="hidden" name="zone_id" id="zone_id" value="<?=intval($data['zone_id']);?>" />
  <input type="hidden" name="parent_id" id="parent_id" value="<?=$pid;?>" />
  <div class="tags">
    <div id="tagstitle"> <a href="#" id="one1" onclick="setTab('one',1,2)" class="hover">基本信息</a> </div>
    <div id="tagscontent">
      <div id="con_one_1">
        <table width="100%" border="0" cellspacing="2" cellpadding="0" id="table1" class="formtable">
          <tr>
            <td width="19%" align="right"><span class="title">区域名称</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="name" id="name" size="40" class="skey" value="<?=h($data['name']);?>" />
              &nbsp;<font color="red">*</font>
              <span class="tips"><a href="javascript:tipsbox('可填写缩略语，或者更完整的称谓');">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">拼音字母</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="ename" id="ename" size="40" class="skey" value="<?=h($data['ename']);?>" />
              &nbsp;<font color="red">*</font>
              <span class="util"><a href="javascript:autoPinyin();">单击这里自动转换</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">首字母</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input name="letter" type="text" class="skey-s" id="letter" value="<?=h($data['letter']);?>" size="10" maxlength="1" /></td>
          </tr>
          <tr>
            <td align="right"><span class="title">区域类型</span></td>
            <td>&nbsp;</td>
            <td>
            <?php
				$zoneTypes = Config::get('system.zone_type');
				$alltype = array_sum(array_keys($zoneTypes));
				foreach($zoneTypes as $idx => $zone){
					$chk = intval($data['zone_type'] & $idx) == $idx ? 'checked' : '';
			?>
                    <p><input name="zonetype[]" type="checkbox" class="skey" id="zonetype-<?=$idx;?>" value="<?=$idx;?>" <?=$chk;?> />
                    <label for="zonetype-<?=$idx;?>"><?=h($zone);?></label></p>
            <?php
				}
            ?>
            </td>
          </tr>
          <tr>
            <td align="right"><span class="title">中心点经度</span></td>
            <td>&nbsp;</td>
            <td><input name="longitude" type="text" class="skey" id="longitude" value="<?=h($data['longitude']);?>" size="40" /></td>
          </tr>
          <tr>
            <td align="right"><span class="title">中心点维度</span></td>
            <td>&nbsp;</td>
            <td><input name="latitude" type="text" class="skey" id="latitude" value="<?=h($data['latitude']);?>" size="40" /></td>
          </tr>
          <tr>
            <td align="right"><span class="title">区域半径</span></td>
            <td>&nbsp;</td>
            <td><input name="radius" type="text" class="skey" id="radius" value="<?=h($data['radius']);?>" size="40" /></td>
          </tr>
          <tr>
            <td align="right"><span class="title">是否显示</span></td>
            <td>&nbsp;</td>
            <td>
            	<input name="display" type="radio" class="skey" id="display-0" value="0" <?php if($data['display'] == 0){ echo 'checked'; }?> />
                <label for="display-0">隐藏</label>
                &nbsp;
                <input name="display" type="radio" class="skey" id="display-1" value="1" <?php if(!isset($data['display']) || $data['display'] > 0){ echo 'checked'; }?> />
                <label for="display-1">显示</label></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
  <div class="blank20"></div>
  <input type="submit" name="dosubmit" value=" 提交 " class="button" />
  <input type="button" onclick="javascript:location.href='<?=Base::adminUrl('dish', 'index', array('res_id' => $res_id));?>'" value=" 返回 " class="button" />
</form>
<script type="text/javascript">
function autoPinyin(){
	$.getJSON(
		'/tools/pinyin',
		{"str" : $("#name").val()},
		function(data) {
		  var pinyin = "";
		  $.each(data, function(key, val){
		  	pinyin += val;
		  });
		  $("#ename").val(pinyin.toLowerCase());
		  $("#letter").val(pinyin.toUpperCase().substring(0,1));
		}
	);
}

function checkZonePinyin(pinyin){
	var res = false;
	$.ajax({
		"url" : "/tools/checkZonePinyin",
		"type" : "get",
		"data" : {"city_id":1, "zone_id":$("#zone_id").val(), "pinyin":pinyin},
		"async" : false,
		"success" : function(data) {
			if(data == "0"){
				res = true; //
			}else{
				res = false; //passed
			}
		}
	});
	return res;
}

function checkSubmit(){
	if ($("#name").val() == "") {
		alert("区域名称没有填写！");
		$("#name").focus();
		return false;
	}

	if (!checkZonePinyin($("#ename").val())){
		alert("拼音名称已存在，请重新设置！");
		$("#ename").focus();
		return false;
	}

	if ($("input[name='zonetype\[\]']:checked").size() == 0) {
		alert("区域类型为空，请至少选择一项！");
		return false;
	}
	return true;
}

$(document).ready(function() {

});
</script>